// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CErrorReportAction.
//   $Id$




#include "IAction.h"
#include <list>

class CErrorReportAction;

//<summary>
//Factory for CErrorReportAction objects.
//</summary>
class CErrorReportActionFactory
{
	typedef std::list<CErrorReportAction *> CErrorActionList;
public:
	//<summary>
	//	static factory method.  Used to ensure that all instances of CErrorReportAction
	//	are stored in the "to delete" list sm_ErrorActions, and can be deleted by a call to Clear().
	//</summary>
	//<parameter name="sError">The error message</parameter>
	//<parameter name="pMessageElement">
	//	A pointer to an IHTMLElement object used to display the error.
	//</parameter>
	//<returns>
	//	A pointer to an initialised CErrorReportAction object<br />
	//	or NULL if either argument is invalid
	//</returns>
	CErrorReportAction * CreateErrorReportAction(const BSTR sError, IHTMLElement * pMessageElement);
	//<summary>
	//	deletes all pending CErrorReportAction objects.
	//</summary>
	void Clear();

private:
	//<summary>
	//	a list of extant CErrorReportAction objects, populated by CreateErrorReportAction and
	//	used by Clear to delete objects when no longer required.
	//</summary>
	CErrorActionList sm_ErrorActions;
};

struct IHTMLElement;

//<summary>
//	Implementation of IAction to display an internally generated error message.
//</summary>
//<remarks>
//	This is used by the Post Modal action system in CXFormsXFormsElement to 
//	display errors in sequence.
//</remarks>
class CErrorReportAction 
	:public IAction
{
	friend class CErrorReportActionFactory;
public:
	//<summary>
	//	Implementation of IAction::Invoke.  
	//	Sets the text of m_pMessageElement and dispatches DOMActivate to it.
	//</summary>
	virtual HRESULT Invoke();
	//<summary>
	//	implementation of IAction::getXFormsElement
	//</summary>
	//<returns>NULL</returns>
	virtual CXFormsXFormsElement * getXFormsElement(){return 0;};
	//<summary>
	//	implementation of IAction::getEvent
	//</summary>
	//<returns>E_NOTIMPL</returns>
	virtual HRESULT getEvent(BSTR * /*sEvent*/){return E_NOTIMPL;};
private:
	//<summary>
	// private constructor to force use of CreateErrorReportAction.
	//</summary>
	//<parameter name="sError">The error message</parameter>
	//<parameter name="pMessageElement">
	//	A pointer to an IHTMLElement object used to display the error.
	//</parameter>
	CErrorReportAction(const BSTR sError, IHTMLElement * pMessageElement)
		:m_sError(sError)
		, m_pMessageElement(pMessageElement)
	{
	};
	//<summary>
	//	The error message.
	//</summary>
	CComBSTR m_sError;
	//<summary>
	//	The message element.
	//</summary>
	CComQIPtr<IHTMLElement> m_pMessageElement;
};
